package com.hfjava.practice03;

import java.io.*;
import java.util.Scanner;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: com.hfjava.practice03
 * @ClassName: CopyFile
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/24 19:18
 * @Copyright 大牛版板所有
 */
public class CopyFile {

    public static void copyFile(String srcPath,String desPath){
        try (DataInputStream dis = new DataInputStream(new FileInputStream(srcPath));
             DataOutputStream dos = new DataOutputStream(new FileOutputStream(desPath))) {
            byte[] bytes = new byte[1024];
            int len = -1;
            while ((len=dis.read(bytes)) != -1){
                dos.write(bytes,0,len);
                dos.flush();

            }
            System.out.println("复制文件成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("请输入一个文件路径：");
        String filePath = input.next();
        File file = new File(filePath);
        if (file.exists()){
            copyFile(filePath,"chapter03\\images\\copy_xm.jpg");
        }
        else {
            System.out.println("你输入的文件不存在！");
        }

    }
}
